package com.xxxx.spark.job

import org.apache.spark.{SparkConf, SparkContext}

object topN {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("uv")
    val sc = new SparkContext(conf)
    val file = sc.textFile("data/scores.txt")

    file.map(line => {
      val strings = line.split(" ")
      (strings(0),strings(1).toInt)
    })
        .groupByKey()
      .map(e => {
        val ints: List[Int] = e._2.iterator.toList.sortWith(_>_).take(3)
        (e._1,ints)
      })
        .foreach(e => {
          println(s"className = ${e._1} , score = ${e._2}")
        })


    sc.stop()
  }


}
